# coding=utf-8
n = int(input())
dic = {}
for i in range(n):
    a = input().split(" ")
    dic.setdefault(int(a[0]), 0)
    dic[int(a[0])] += int(a[1])

dic = sorted(dic.items(), key=lambda x: x[0])

for j in dic:
    print(j[0], j[1])
